'''
----------------------
端口扫描类
'''

from socket import *
import  threading

class ScanPort():
    def __init__(self,ip,startPort,endPort):
        self.scanIp=ip
        self.startPort=startPort
        self.endPort = endPort
        #存储数据
        self.textList=[]

    #发送数据
    def sendRequest(self,ip,port):
        s=socket(AF_INET,SOCK_STREAM)
        s.settimeout(1)
        try:
            s.connect((ip,port))
            txt = "[+]:" + ip + " -> " +str(port) + "is open"
            self.saveList(txt)
        except:
            pass
        finally:
            s.close()

    #扫描
    def Scaning(self):
        for port in range(int(self.startPort),int(self.endPort)):
            t=threading.Thread(target=self.sendRequest,args=(self.scanIp,port))
            t.setDaemon(False)
            t.start()

    #保存数据
    def saveList(self,txt):
        self.textList.append(txt)

